package com.ruoyi.bom.controller;

import com.ruoyi.bom.domain.TqlMaterialTransfer;
import com.ruoyi.bom.service.TqlKingdeeTransferService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
import java.util.Map;

/**
 * @Author: Jzh
 * @Date: 2024-01-24  19:07
 */
@RestController
@Api(tags = "库存管理-调拨管理")
@RequestMapping("/material/transfer")
public class TqlKingdeeTransferController extends BaseController {

    @Autowired
    private TqlKingdeeTransferService tqlKingdeeTransferService;

    @RequiresPermissions("material:transfer:page")
    @ApiOperation("调拨分页")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "date", value  = "日期", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "createBy", value = "操作人", paramType = "query", dataType = "string")
    })
    @GetMapping("/page")
    public TableDataInfo list(@ApiIgnore @RequestParam Map<String, String> params) {
        startPage();
        List<TqlMaterialTransfer> list = tqlKingdeeTransferService.selectTransferList(params);
        return getDataTable(list);
    }

    @RequiresPermissions("material:transfer:add")
    @ApiOperation("添加调拨")
    @Log(title = "添加调拨", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody List<TqlMaterialTransfer> dtoList) {
        //获取用户信息
        tqlKingdeeTransferService.add(dtoList);
        return success();
    }

    @ApiOperation("获取调拨信息")
    @RequiresPermissions("material:transfer:query")
    @GetMapping(value = "/getInfo")
    public AjaxResult getInfo(@RequestParam("fbillno") String fbillno,
                              @RequestParam("month") Integer month, @RequestParam("FMaterialId") String FMaterialId) {
        if (fbillno == null || month == null ) {
            return error("参数错误！");
        }
        List<TqlMaterialTransfer> dataList = tqlKingdeeTransferService.getByFbillno(fbillno, month, FMaterialId);
        return success(dataList);
    }

    @RequiresPermissions("material:transfer:update")
    @Log(title = "修改调拨", businessType = BusinessType.UPDATE)
    @ApiOperation("修改调拨")
    @PutMapping("/update")
    public AjaxResult update(@RequestBody List<TqlMaterialTransfer> dtoList) {
        tqlKingdeeTransferService.update(dtoList);
        return success();
    }
}
